package offer;

/**
 * @author SSK
 * @Description 数组中只出现一次的数字
 *
 */
public class T41 {
    public void FindNumsAppearOnce(int [] array,int num1[] , int num2[]) {
        int num1XorNum2 = getsXOr(array,array.length);
        int x = num1XorNum2&-num1XorNum2;
        int[] array1 = new int[array.length];
        int[] array2 = new int[array.length];
        int cnt1 = 0;
        int cnt2 = 0;
        for (int i = 0; i < array.length; i++) {
            if ((array[i]&x)!=0) {
                array1[cnt1++] = array[i];
            }else {
                array2[cnt2++] = array[i];
            }
        }
        num1[0] = getsXOr(array1,cnt1);
        num2[0] = getsXOr(array2,cnt2);
    }
    public int getsXOr(int[] array , int size) {
        if (size==1) {
            return array[0];
        }
        int num = array[0];
        for (int i = 1; i < size; i++) {
            num^=array[i];
        }
        return num;
    }
    public static void main ( String[] args) {
        new T41().FindNumsAppearOnce(new int[]{4,6,2,2,3,3,8,8,9,9,1000000,1000000},new int[2],new int[3]);

    }
}


